package com.controller;

import com.comment.CommentResult;
import com.domain.entity.Assort;
import com.service.AssortService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@CrossOrigin//跨越
@RestController
@Slf4j
@RequestMapping("/assort")
public class AssortController {

    @Autowired
    private AssortService assistService;

    /**
     * 新增分类
     */
    @PostMapping("/addAssort")
    public CommentResult<Void> addAssort(@RequestBody String name) {
        assistService.addAssort(name);
        return CommentResult.success();
    }


    /**
     * 获取所有分类信息
     */
    @GetMapping("/list")
    public CommentResult<List<Assort>> list() {
        List<Assort> assortList = assistService.list();
        return CommentResult.success(assortList);
    }

    /**
     * 根据id删除分类信息
     */
    @DeleteMapping("/deleteById/{id}")
    public CommentResult<Void> deleteById(@PathVariable("id") Integer id) {
        assistService.deleteById(id);
        return CommentResult.success();
    }
}
